package com.wjw.java.others.innerClass_;

/**
 * 匿名内部类：最佳实战,当做实参直接传递
 * 1.声明一个接口ImageService,接口中有一个抽象方法show()
 * 2.声明一个static的静态方法showImg(ImageService imageService){
 *     imageService.show();
 * }
 * 3.调用showImg(new ImageService(){
 *     @Override
 *     public void show() {
 *         //...
 *     }
 * });
 */
public class AnonymousInnerClassExercise {
    public static void main(String[] args) {
        //1.传统写法一
        ImageService imageService = new ImageServiceImpl();
        imageService.show();
        //2.传统写法二
        showImg(new ImageServiceImpl());
        //3 .匿名内部类,作为方法的实参
        showImg(new ImageService() {
            @Override
            public void show() {
                System.out.println("匿名内部类：重写show()");
            }
        });
    }
    public static void showImg(ImageService imageService){
        imageService.show();
    }
}
//接口:ImageService
interface ImageService{
    void show();
}
//接口实现类:ImageServiceImpl
class ImageServiceImpl implements ImageService{
    @Override
    public void show() {
        System.out.println("接口实现类：重写show()");
    }
}